package Main;

import java.io.IOException;

import Gui.ButtonClass;
import Gui.GameFrame;
import GameFiles.GameManager;
import GameStates.MainMenu;
import EventManager.EventManager;
import EventManager.GameListener;
import EventManager.StateMachineListener;

public class PayDayMain {
	public static void init() throws IOException {
		// Set up the Event Manager

	}

	public static void main(String[] args) throws IOException {
		/**
		 * Initialization
		 */
		// Test
		GameManager.getInstance().InitializeGame();

//		// TODO - remove these test calls:
//		Defines.GM.initializeDealCards();
//		Defines.GM.initializeMailCards();
//		Defines.GM.PopulateDealCards();
//		Defines.GM.PopulateMailCards();

		// Create the screen
		// GameFrame.getInstance().setVisible(true);, caused multiple windows
		/**
		 * Game Loop
		 */
		long soon = 0;
		long now = System.currentTimeMillis();
		while (true) {
			//System.out.println(GameManager.getInstance().getCurrentGameState());
			// Throttle
			now = System.currentTimeMillis();
			if (now >= soon) {
				// Throttle
				soon = now + 10;
				// Draw
				//GameFrame.getInstance().getContentPane().repaint();
				GameFrame.getInstance().repaint();
				// Update Monitoring system
				// TODO add actual time passed to UpdateProcesses
				EventManager.getInstance().processEvents();
				// Update Game Logic
				GameManager.getInstance().getCurrentGameState().Execute();

			} else {
				// Professor said you have to try/catch sleep I don't remember
				// why
				try {
					Thread.sleep(1);
				} catch (Exception e) {
				}
			}
		}
	}
}
